home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS14.ADF
/
Tool
/
select.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-01-28
|
4KB
|
152 lines
/*
SELECT.C Copyright Daniel D. Kary 1986
Standard Listing
*/
#include <libraries/dos.h>
#include <stdio.h>
FILE *fout;
main(argc, argv)
int argc;
char *argv[];
{
int i;
if(argc < 3){
printf("USAGE: %s infile(s) outfile\n", argv[0]);
exit(1);
}
argc--;
if((fout = fopen(argv[argc], "w")) == NULL){
printf("Unable to write to %s\n", argv[argc]);
exit(1);
}
for(i = 1; i < argc; i++)
search(argv[i]);
}
search(name)
char *name;
/* recursively search "name" for files */
{
struct FileInfoBlock *FIB, *AllocMem();
int lock;
char *subdir;
if((FIB= AllocMem(sizeof(struct FileInfoBlock),0))==0){
printf("Can not allocate memory for FIB\n");
return(0);
}
if((lock = Lock(name, SHARED_LOCK)) == 0){
printf("Can not Lock %s\n", name);
FreeMem(FIB, sizeof(struct FileInfoBlock));
return(0);
}
if((Examine(lock, FIB)) == 0){
printf("Can not Examine %s\n", name);
UnLock(lock);
FreeMem(FIB, sizeof(struct FileInfoBlock));
return(0);
}
if(FIB->fib_DirEntryType > 0){
printf("%s (dir)\n", name);
while(ExNext(lock, FIB)){
subdir = (char *) malloc(strlen(name)+
strlen(&FIB->fib_FileName[0])+2);
strcpy(subdir, name);
if(not_device(name))
strcat(subdir, "/");
strcat(subdir, &FIB->fib_FileName[0]);
if(FIB->fib_DirEntryType > 0)
search(subdir);
else{
printf("%s\n", subdir);
read_file(subdir);
}
free(subdir);
}
}
else{
printf("%s\n", name);
read_file(name);
}
UnLock(lock);
FreeMem(FIB, sizeof(struct FileInfoBlock));
}
not_device(name)
char name[];
/* return TRUE if the last char is not a colon */
{
int i, j;
for( i = 0; name[i]; i++){
if(name[i] == ':')
j = FALSE;
else
j = TRUE;
}
return(j);
}
read_file(name)
char *name;
/* find all the struct definitions in the named file
* and write them on the users output file
*/
{
FILE *fin;
char buf1[256], buf2[256], buf3[256];
int Found1, Found2, count, q, i, j;
if((fin = fopen(name, "r")) == NULL){
printf("Unable to read %s\n", name);
return(0);
}
while((fgets(&buf1[0], 256, fin)) != NULL){
if(strncmp(&buf1[0], "struct", 6) == 0){
Found1 = Found2 = FALSE;
if(stcpm(&buf1[0], "{", &q)){
count = 1;
Found1 = TRUE;
}
else{
if((fgets(&buf2[0], 256, fin)) != NULL){
if(stcpm(&buf2[0], "{", &q)){
count = 1;
Found2 = TRUE;
}
}
}
if(Found1 || Found2){
for(i = 6; !isalpha(buf1[i]); i++);
for(j = 0; isalpha(buf1[i]); i++, j++)
buf3[j] = buf1[i];
buf3[j] = '\0';
fprintf(fout,"!%s\n", &buf3[0]);
fprintf(fout,"%s\n", name);
fprintf(fout,"%s",&buf1[0]);
}
if(Found2)
fprintf(fout,"%s",&buf2[0]);
while(Found1 || Found2){
if((fgets(&buf1[0], 256, fin)) != NULL)
fprintf(fout,"%s",&buf1[0]);
else{
fclose(fin);
return(0);
}
if(stcpm(&buf1[0], "{", &q))
count++;
if(stcpm(&buf1[0], "}", &q))
if(--count == 0)
Found1 = Found2 = FALSE;
}
}
}
fclose(fin);
}